package flst.ipiweb.service;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

import flst.ipiweb.common.Command;
import flst.ipiweb.common.CommandLine;
import flst.ipiweb.common.DeliveryRecipient;
import flst.ipiweb.dao.DAOFactory;
import flst.ipiweb.exceptions.IPIWebException;

public class ServiceCommande {

	public int getNumberOfCommand(Date day) {

		try {
			List<Integer> list = DAOFactory.getCommandDAO().getNumberOfCommand(day);
			if (list != null && list.size() > 0) {
				return list.get(0);
			} else {
				return -1;
			}
		} catch (IPIWebException e) {
			return -1;
		}

	}

	public List<Integer> getNumberOfCommand(Date... days) {

		try {
			List<Integer> list = DAOFactory.getCommandDAO().getNumberOfCommand(days);

			if (list == null) {
				list = new ArrayList<Integer>();
			}

			return list;

		} catch (IPIWebException e) {
			return new ArrayList<Integer>();
		}

	}

	public Command getCommandById(int idCommande) {

		try {
			return DAOFactory.getCommandDAO().getCommandById(idCommande);

		} catch (IPIWebException e) {
			return new Command();
		}

	}

	public List<CommandLine> getLignesCommandeByIdCommand(int idCommande) {

		try {
			return DAOFactory.getCommandDAO().getLignesCommandeByIdCommand(idCommande);

		} catch (IPIWebException e) {
			return new ArrayList<CommandLine>();
		}

	}
	
	public void validCommande(int idCommande) {

		try {
			DAOFactory.getCommandDAO().validCommande(idCommande);

		} catch (IPIWebException e) {
			
		}

	}
	
	
	public DeliveryRecipient getInfosRelaisByIdCommand(int idCommande) {

		try {
			return DAOFactory.getCommandDAO().getInfosRelaisByIdCommand(idCommande);

		} catch (IPIWebException e) {
			return new DeliveryRecipient();
		}

	}
	
}
